package com.zimin.cloud.web.controller;

import com.zimin.shared.pojo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @author zimin
 * @since 2021/10/29 1:37 下午
 */
@RestController
public class TestController {

    @GetMapping("/test")
    public Mono<Result> test() {
        return Mono.just(Result.ok("hehehe"));
    }

    @GetMapping(value = "/fluxTest",produces = "text/event-stream")
    public Flux<String> flux() {
        return Flux.fromStream(IntStream.range(1, 5).mapToObj(i -> {
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "flux-data--" + i;
        }));
    }

}
